<?php
namespace app\shop\controller;
use think\Controller;
use think\Db;

class Common extends Controller{
    public $webconfig;
    
    Public function _initialize(){
//        if(!session('shopadmin_id') || !session('shopsh_id')){
//            $this->redirect('login/index');
//        }

        if(!session('shopadmin_id') || !session('shopsh_id')){
            $token = input('get.token');
            if($token){
                $shopadminId = db('member_token')->where('token',input('get.token'))->value('shop_admin_id');
                $shopshId  = db('shop_admin')->where('id',$shopadminId)->value('shop_id');
                if($shopadminId && $shopshId){
                    session('shopadmin_id',$shopadminId);
                    session('shopsh_id',$shopshId);
                    session('client','mobile');
                }else{
//                    $this->redirect('login/tips');
                    echo "<script>alert('token错误');</script>";
                    die;
                }
            }else{
                $this->redirect('login/index');
            }
        }


        $this->_getconfig();

        // 微信小程序支付配置
        $wxpayRes=db('wxpay_config')->where('id',1)->find();
        $this->wechatPayConfig = [
            // 前面的appid什么的也得保留哦
            'app_id'             => $wxpayRes['appid'],
            'mch_id'             => $wxpayRes['mch_id'],
            'key'                => $wxpayRes['api_key'],
            'cert_path'          => '/www/wwwroot/demo.wo-shop.net/cert/apiclient_cert.pem', // 绝对路径！！！！
            'key_path'           => '/www/wwwroot/demo.wo-shop.net/cert/apiclient_key.pem',      // 绝对路径！！！！
            //'notify_url'         => $configres['weburl'].'/api/Wxpay/wxNotify',     // 你也可以在下单时单独设置来想覆盖它
        ];
    }
    
    public function _getconfig(){
        $_configres = Db::name('config')->field('ename,value')->select();
        $configres = array();
        foreach ($_configres as $v){
            $configres[$v['ename']] = $v['value'];
        }
        $this->webconfig=$configres;
        $this->assign('configres',$configres);
    }
    
}